import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

public class POI {
    public static void main(String[] args) throws IOException {
        write();
    }
    public static void write() throws IOException {
        XSSFWorkbook workbook = new XSSFWorkbook();//在内存中创建一个Excel
        XSSFSheet sheet = workbook.createSheet("info");//在Excel文件中创建一个sheet页
        XSSFRow row = sheet.createRow(0);//rownum：行索引(从0开始)
        row.createCell(0).setCellValue("name");
        row.createCell(1).setCellValue("age");
        row.createCell(2).setCellValue("height(kg)");
        XSSFRow row1 = sheet.createRow(1);
        row1.createCell(0).setCellValue("方源");
        row1.createCell(1).setCellValue("500");
        row1.createCell(2).setCellValue("80");
        row.getCell(0).setCellValue("姓名");

        //通过输出流保存到指定的盘符位置
        FileOutputStream fileOutputStream = new FileOutputStream(new File("D:\\info_1.xlsx"));
        workbook.write(fileOutputStream);

        //关闭资源
        fileOutputStream.close();
        workbook.close();

    }
}
